import { doLogin } from '@/api/user/user';
import { Button, Form, Input, message } from 'antd';
import { useHistory } from 'umi';
function index() {
  const history = useHistory();
  const login = (user: API.IUser) => {
    doLogin(user).then((res) => {
      console.log(res);
      if (res.code === 0) {
        history.push('/');
      } else {
        message.error('登陆失败');
      }
    });
  };
  return (
    <>
      <Form
        labelCol={{ span: 8 }}
        wrapperCol={{ span: 16 }}
        initialValues={{ name: '', password: '' }}
        onFinish={login}
      >
        <Form.Item
          label="用户名"
          name={'name'}
          rules={[
            {
              type: 'string',
              required: true,
              message: '用户名不可以为空',
            },
          ]}
        >
          <Input />
        </Form.Item>
        <Form.Item
          label="密码"
          name={'password'}
          rules={[
            {
              type: 'string',
              required: true,
              message: '密码不可以为空',
            },
          ]}
        >
          <Input.Password />
        </Form.Item>
        <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
          <Button type="primary" htmlType="submit">
            登录
          </Button>
        </Form.Item>
      </Form>
    </>
  );
}
export default index;
